package com.example.designpattenexample.visitor;

import java.util.Random;
import java.util.Vector;

public class ObjectStructure {
    private Vector<Element> elements;
    public ObjectStructure(){
        elements = new Vector<>();
    }

    public void add(Element e){
        elements.add(e);
    }

    public Vector<Element> createElements(){
        Random random = new Random();
        for (int i=0;i<10;i++){
            if (random.nextInt(100)<50)
                this.add(new Element1());
            else
                this.add(new Element2());
        }
        return this.elements;
    }

    public void action(Visitor visitor){
        for (Element e : elements){
            e.accept(visitor);
        }
    }

}
